package com.sgb.kjwl.view.ui.activity.transport.driver.lines;

import android.app.Activity;
import android.content.Context;
import androidx.databinding.ViewDataBinding;
import android.view.View;

import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ItemLinesListBinding;
import com.sgb.kjwl.view.ui.adapter.AppRecyclerAdapter;

/**
 * Created by harisucici
 * Class description:常跑线路 Adapter
 */
public class LineSettingAdapter extends AppRecyclerAdapter<LinesItemEntity, ItemLinesListBinding> {
    private BindingListenAdd itemAdd;
    private BindingListenAddress1 itemAddress1;
    private BindingListenAddress2 itemAddress2;
    private BindingListenDel itemDel;
    private Context context;


    public LineSettingAdapter(Activity context,
                              BindingListenAdd<LinesItemEntity, ItemLinesListBinding> itemAdd,
                              BindingListenDel<LinesItemEntity, ItemLinesListBinding> itemDel,
                              BindingListenAddress1<LinesItemEntity, ItemLinesListBinding> itemAddress1,
                              BindingListenAddress2<LinesItemEntity, ItemLinesListBinding> itemAddress2
    ) {
        super(context);
        this.itemAdd = itemAdd;
        this.itemDel = itemDel;
        this.itemAddress1 = itemAddress1;
        this.itemAddress2 = itemAddress2;
        this.context = context;
    }

    @Override
    protected int getLayoutResId(int viewType) {
        return R.layout.item_lines_list;
    }

    @Override
    protected void onBindItem(final ItemLinesListBinding binding, final LinesItemEntity entity, final int position) {
        if (position == mList.size()-1 ) {
            binding.linesTitle.setVisibility(View.VISIBLE);
            binding.linesDetail.setVisibility(View.GONE);

        }else{
            binding.linesTitle.setVisibility(View.GONE);
            binding.linesDetail.setVisibility(View.VISIBLE);
        }
        if (mList.size()==6){
            binding.linesTitle.setVisibility(View.GONE);
            binding.linesDetail.setVisibility(View.VISIBLE);
        }
        binding.linesTitle.setOnClickListener((v) -> {
            itemAdd.onItemClick(binding, entity, position);
        });
        binding.linesDel.setOnClickListener((v) -> {
            itemDel.onItemClick(binding, entity, position);
        });
        binding.linesAddress1.setOnClickListener((v) -> {
            itemAddress1.onItemClick(binding, entity, position);
        });
        binding.linesAddress2.setOnClickListener((v) -> {
            itemAddress2.onItemClick(binding, entity, position);
        });

        binding.setEntity(entity);
        binding.executePendingBindings();
    }


    @FunctionalInterface
    public interface BindingListenAdd<T, B extends ViewDataBinding> {
        void onItemClick(B binding, T t, int i);

    }

    @FunctionalInterface
    public interface BindingListenDel<T, B extends ViewDataBinding> {
        void onItemClick(B binding, T t, int i);

    }

    @FunctionalInterface
    public interface BindingListenAddress1<T, B extends ViewDataBinding> {
        void onItemClick(B binding, T t, int i);

    }

    @FunctionalInterface
    public interface BindingListenAddress2<T, B extends ViewDataBinding> {
        void onItemClick(B binding, T t, int i);

    }

}